package com.ruoyi.base.controller;

import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.ruoyi.base.domain.SubjectType;
import com.ruoyi.base.domain.dto.SubjectReqDto;
import com.ruoyi.base.service.ISubjectTypeService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 科目类型Controller
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/subjectType")
public class SubjectTypeController extends BaseController
{
    @Autowired
    private ISubjectTypeService subjectTypeService;

    /**
     * 查询科目类型列表
     */
    @RequiresPermissions("voucher:subjectType:list")
    @GetMapping("/list")
    public TableDataInfo list(SubjectType subjectType)
    {
        startPage();
        List<SubjectType> list = subjectTypeService.selectSubjectTypeList(subjectType);
        return getDataTable(list);
    }

    /**
     * 导出科目类型列表
     */
    @RequiresPermissions("voucher:subjectType:export")
    @Log(title = "科目类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SubjectType subjectType)
    {
        List<SubjectType> list = subjectTypeService.selectSubjectTypeList(subjectType);
        ExcelUtil<SubjectType> util = new ExcelUtil<SubjectType>(SubjectType.class);
        util.exportExcel(response, list, "科目类型数据");
    }

    /**
     * 获取科目类型详细信息
     */
    @RequiresPermissions("voucher:subjectType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(subjectTypeService.selectSubjectTypeById(id));
    }

    /**
     * 新增科目类型
     */
    @RequiresPermissions("voucher:subjectType:add")
    @Log(title = "科目类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SubjectType subjectType)
    {
        return toAjax(subjectTypeService.insertSubjectType(subjectType));
    }

    /**
     * 修改科目类型
     */
    @RequiresPermissions("voucher:subjectType:edit")
    @Log(title = "科目类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SubjectType subjectType)
    {
        return toAjax(subjectTypeService.updateSubjectType(subjectType));
    }

    /**
     * 删除科目类型
     */
    @RequiresPermissions("voucher:subjectType:remove")
    @Log(title = "科目类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(subjectTypeService.deleteSubjectTypeByIds(ids));
    }
}
